// Copyright Leonid Shlyapnikov 2010
// Distributed under the GNU Lesser General Public License http://www.gnu.org/licenses/lgpl.html
//    author: Leonid Shlyapnikov, created on: Feb 13, 2010

#ifndef FIXPARSER_CPP_SRC_MAIN_FIXPARSER_STRING_H_
#define FIXPARSER_CPP_SRC_MAIN_FIXPARSER_STRING_H_

#include <boost/exception/all.hpp>
#include <string>
#include <sstream>
#include <cstring>

#include "./Base.h"

namespace fixparser {

class MemoryArea;

class String: public Base {
public:
    explicit String(MemoryArea* const memoryArea);
    virtual ~String();

    const char* c_str() const { return  this->str_; }
    size_t length() const { return this->length_; }

//    void set_char(size_t index, const char ch) {
//        if (index >= length_ ||  index < 0) {
//            std::stringstream errorMsg;
//            errorMsg << "index out of range, index: " << index << " String.length_: "  << this->length_;
//            BOOST_THROW_EXCEPTION(std::out_of_range(errorMsg.str()));
//        }
//        this->str_[index] = ch;
//    }

    String& assign(const char* new_str, size_t new_length);
    String& assign(const char* str);
    String& assign(const String& that);
    String& assign(const std::string& that);

    void copy_in(const char* new_str, size_t new_length);
    void copy_in(const String& that);

private:
    void set(const char* new_str, size_t new_length);

    const char* str_;
    size_t length_;
    MemoryArea* const memoryArea_;
};

}

#endif  // FIXPARSER_CPP_SRC_MAIN_FIXPARSER_STRING_H_
